<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<script>
function deleteShow(){
	$(".deleteClass").show();
	$("#deleteIcon").hide();
	$("#cancelIcon").show();
	//$(".checkButton").show();
	document.getElementById("checkButton").style.display = "block";
	$(".deleteClassChecked").hide();
	refleshAllCodes();
}
function deleteCancel(){
	$(".deleteClass").hide();
	$("#deleteIcon").show();
	$("#cancelIcon").hide();
	//$(".checkButton").hide();
	document.getElementById("checkButton").style.display = "none";
	$(".deleteClassChecked").hide();
	
	//去掉取消全选状态
	var check = document.getElementById("check_all"); 
	var text = check.innerText;
	if(text == "取消全选"){
		check.innerText = "全选";
	}
	
	refleshAllCodes();
}
function checkAll(){
	var check = document.getElementById("check_all"); 
	var text = check.innerText;
	if(text == "全选"){
		$(".deleteClassChecked").show();
		$(".deleteClass").hide();
		check.innerText = "取消全选";
	}else {
		$(".deleteClassChecked").hide();
		$(".deleteClass").show();
		check.innerText = "全选";
	}
	refleshAllCodes();
}
function check(id){
	switchStatus(id);
	refleshAllCodes();
}
function uncheck(id){
	switchStatus(id);
	refleshAllCodes();
}
function switchStatus(id){
	$("#"+id).toggle();
	$("#un"+id).toggle();
}
var selectCodes = new Array();
var selectIds = new Array();
function refleshAllCodes(){
	selectCodes = new Array();
	selectIds = new Array();
	$(".deleteClassChecked").each(function(index,ele){
		if($(ele).css("display")== "block"){
			selectCodes.push($("#"+ele.id+"_val").val());
			selectIds.push(ele.id);
		}
	});
	if(selectCodes.length > 0){
		$("#deleteCount").html("删除("+selectCodes.length+")");
	}else{
		$("#deleteCount").html("删除");
	}
}
function playContent(type,contentCode,prog,title,icon){
	if($(".checkButton").css("display") != "none"){
		return;
	}else{
		var content = new EpgContent(type,contentCode,'',title,icon);
		stbs = weixinOption.bind; 
		if(stbs.length >= 1){
		    content.stbNo = stbs[0].stbNo;
			stbCtrl.play(content);
		}else{
			gotoLink("${personUrl}");
		}
	}
}
function showEmptyImage(){
	document.getElementById("empty_image").style.display = "block";
}

function listContent(url,data){
	$.ajax({
		method:"get",
		url:url,
		data:data,
		success:function(data){
			/*console.log("log personlist:");
			console.log(data);*/
			if(data.resultSet){
				vm.content = data.resultSet;
				if(vm.type=="history"){
					vm.content = removeSame(vm.content);
				}
				refreshLocalStorage();
			}else{
				vm.content = [];
			}
			if(vm.content.length == 0){
				showEmptyImage();
			}
		},
		error:function(){
			showEmptyImage();
		}
	});
}
function removeSame(contentList){
	var arr = [];
	for(var i=0;i<contentList.length;i++){
		var idx = -1;
		for(var j=0;j<arr.length;j++){
			if(contentList[i].contentCode == arr[j].contentCode){
				idx = j;
				break;
			}
		}
		if(idx == -1 && contentList[i].cmd == 'play'){
			arr.push(contentList[i]);
		}
	}
	return arr;
}
function getCreateTime(longtime){
	var time = new Date(longtime);
	var mon = time.getMonth()+1;
	var day = time.getDate();
	var hours = time.getHours();
	if(hours < 10){
		hours  = '0'+hours;
	}
	var mins = time.getMinutes();
	if(mins < 10){
		mins = '0'+mins;
	}
	return mon+"月"+day+"日 "+hours+":"+mins;
}
function isToday(longtime){
	var time = new Date(longtime);
	var mon = time.getMonth();
	var day = time.getDate();
	
	var now = new Date();
	var monh = now.getMonth();
	var dayh = now.getDate();
	if(mon==monh&&day==dayh){
		return true;
	}else{
		return false;
	}
}
function getDeltailUrl(type,contentCode,icon,epiCode,title){
	var path = "${_contextPath}/${_context.siteCode}/${_context.bizCode}/-/-/det/"+type+"/"+contentCode+".wx";
	if(vm.type=="history" && type.indexOf("series")!=-1){
		path = addUrlParameter(path,"epiCode",epiCode);
	}
	return path;
}
function getDeltailUrlOfChannel(type,contentCode,icon,epiCode,title){
	var path = "${_contextPath}/${_context.siteCode}/${liveBizCode}/-/-/det/channel/"+contentCode+".wx";
	path = addUrlParameter(path,"icon",icon);
	//截取频道名称作为title
	if(type == "schedule"){
		var chanelTitle = title;
		var idx = chanelTitle.indexOf(":");
		if(idx != -1){
			chanelTitle = title.substring(0,title.indexOf(":"));
		}
		path = addUrlParameter(path,"title",chanelTitle);
	}
	return path;
} 
function personPlay(type,code,prog,title,icon){
	/* var params = {
		userId:'${EPG_USER_SESSION.userId}',
		type:type,
		code:code,
		prog:prog,
		title:title,
		icon:icon
	}
	play(params,"${personUrl}","personplay");
	setTimeout(function(){
		gotoLink(getDeltailUrl(type,code),"personplay");
	},4000); */
	//收藏没有传prog
	var contentCode = prog;
	if(vm.type == "collect" || type == "vod"){
		contentCode = code;
	}
	if(type == "schedule"|| type == "channel"){
		gotoLink(getDeltailUrlOfChannel(type,contentCode,icon,code,title),"personplay");
	}else{
		gotoByEnableStatus(type,contentCode,icon,code,title);
	}
}
function gotoByEnableStatus(type,contentCode,icon,code,title){
	$.ajax({
		method:"get",
		url:"${_contextPath}/api/enableStatus/"+contentCode+".json",
		success:function(data){
			if(data.result){
				gotoLink(getDeltailUrl(type,contentCode,icon,code,title),"personplay");
			}else{
				alertUnable();
			}
		},
		error:function(){
			alertUnable();
		}
	});
}
function alertUnable(){
	$("#notOnLine").show();
	setTimeout(function(){
		$("#notOnLine").hide();
	},800);
}
</script>